/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Tbv_caja_monedaDAOImpl implements orm.dao.Tbv_caja_monedaDAO {
	public Tbv_caja_moneda loadTbv_caja_monedaByORMID(int cm_id_caja_monedas) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_caja_monedaByORMID(session, cm_id_caja_monedas);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda getTbv_caja_monedaByORMID(int cm_id_caja_monedas) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_caja_monedaByORMID(session, cm_id_caja_monedas);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda loadTbv_caja_monedaByORMID(int cm_id_caja_monedas, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_caja_monedaByORMID(session, cm_id_caja_monedas, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda getTbv_caja_monedaByORMID(int cm_id_caja_monedas, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_caja_monedaByORMID(session, cm_id_caja_monedas, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda loadTbv_caja_monedaByORMID(PersistentSession session, int cm_id_caja_monedas) throws PersistentException {
		try {
			return (Tbv_caja_moneda) session.load(orm.Tbv_caja_moneda.class, new Integer(cm_id_caja_monedas));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda getTbv_caja_monedaByORMID(PersistentSession session, int cm_id_caja_monedas) throws PersistentException {
		try {
			return (Tbv_caja_moneda) session.get(orm.Tbv_caja_moneda.class, new Integer(cm_id_caja_monedas));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda loadTbv_caja_monedaByORMID(PersistentSession session, int cm_id_caja_monedas, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_caja_moneda) session.load(orm.Tbv_caja_moneda.class, new Integer(cm_id_caja_monedas), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda getTbv_caja_monedaByORMID(PersistentSession session, int cm_id_caja_monedas, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_caja_moneda) session.get(orm.Tbv_caja_moneda.class, new Integer(cm_id_caja_monedas), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda[] listTbv_caja_monedaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_caja_monedaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda[] listTbv_caja_monedaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_caja_monedaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda[] listTbv_caja_monedaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_caja_moneda as Tbv_caja_moneda");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Tbv_caja_moneda[]) list.toArray(new Tbv_caja_moneda[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda[] listTbv_caja_monedaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_caja_moneda as Tbv_caja_moneda");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Tbv_caja_moneda[]) list.toArray(new Tbv_caja_moneda[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda loadTbv_caja_monedaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_caja_monedaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda loadTbv_caja_monedaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_caja_monedaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda loadTbv_caja_monedaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tbv_caja_moneda[] tbv_caja_monedas = listTbv_caja_monedaByQuery(session, condition, orderBy);
		if (tbv_caja_monedas != null && tbv_caja_monedas.length > 0)
			return tbv_caja_monedas[0];
		else
			return null;
	}
	
	public Tbv_caja_moneda loadTbv_caja_monedaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tbv_caja_moneda[] tbv_caja_monedas = listTbv_caja_monedaByQuery(session, condition, orderBy, lockMode);
		if (tbv_caja_monedas != null && tbv_caja_monedas.length > 0)
			return tbv_caja_monedas[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTbv_caja_monedaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_caja_monedaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_caja_monedaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_caja_monedaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_caja_monedaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_caja_moneda as Tbv_caja_moneda");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_caja_monedaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_caja_moneda as Tbv_caja_moneda");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda createTbv_caja_moneda() {
		return new orm.Tbv_caja_moneda();
	}
	
	public boolean save(orm.Tbv_caja_moneda tbv_caja_moneda) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().saveObject(tbv_caja_moneda);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Tbv_caja_moneda tbv_caja_moneda) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().deleteObject(tbv_caja_moneda);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_caja_moneda tbv_caja_moneda)throws PersistentException {
		try {
			if(tbv_caja_moneda.getTbv_tipo_caja_monedatc_id_tipo_caja_moneda() != null) {
				tbv_caja_moneda.getTbv_tipo_caja_monedatc_id_tipo_caja_moneda().tbv_caja_moneda.remove(tbv_caja_moneda);
			}
			
			orm.Tbv_maquina[] lTbv_maquinas = tbv_caja_moneda.tbv_maquina.toArray();
			for(int i = 0; i < lTbv_maquinas.length; i++) {
				lTbv_maquinas[i].setTbv_caja_monedacm_id_caja_monedas(null);
			}
			return delete(tbv_caja_moneda);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_caja_moneda tbv_caja_moneda, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(tbv_caja_moneda.getTbv_tipo_caja_monedatc_id_tipo_caja_moneda() != null) {
				tbv_caja_moneda.getTbv_tipo_caja_monedatc_id_tipo_caja_moneda().tbv_caja_moneda.remove(tbv_caja_moneda);
			}
			
			orm.Tbv_maquina[] lTbv_maquinas = tbv_caja_moneda.tbv_maquina.toArray();
			for(int i = 0; i < lTbv_maquinas.length; i++) {
				lTbv_maquinas[i].setTbv_caja_monedacm_id_caja_monedas(null);
			}
			try {
				session.delete(tbv_caja_moneda);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Tbv_caja_moneda tbv_caja_moneda) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().refresh(tbv_caja_moneda);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Tbv_caja_moneda tbv_caja_moneda) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().evict(tbv_caja_moneda);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_moneda loadTbv_caja_monedaByCriteria(Tbv_caja_monedaCriteria tbv_caja_monedaCriteria) {
		Tbv_caja_moneda[] tbv_caja_monedas = listTbv_caja_monedaByCriteria(tbv_caja_monedaCriteria);
		if(tbv_caja_monedas == null || tbv_caja_monedas.length == 0) {
			return null;
		}
		return tbv_caja_monedas[0];
	}
	
	public Tbv_caja_moneda[] listTbv_caja_monedaByCriteria(Tbv_caja_monedaCriteria tbv_caja_monedaCriteria) {
		return tbv_caja_monedaCriteria.listTbv_caja_moneda();
	}
}
